package com.rjpacket.chileme.app.tasks;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.widget.ImageView;
import com.rjpacket.chileme.app.utils.HttpTool;

/**
 * Created by WIN7 on 2015/3/24.
 */
public class StoreIconTask extends AsyncTask<String, Integer, Bitmap> {

    private ImageView imageView;

    public StoreIconTask(ImageView imageView) {
        this.imageView = imageView;
    }

    @Override
    protected Bitmap doInBackground(String... params) {

        Bitmap ret = null;

        if (params != null && params.length > 0) {
            String url = params[0];
            byte[] bytes = HttpTool.get(url);
            ret = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
        }

        return ret;
    }

    @Override
    protected void onPostExecute(Bitmap bitmap) {
        if (bitmap != null) {
            if (imageView!=null){
                imageView.setImageBitmap(bitmap);
            }
        }
    }
}
